﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace LinqToLfsWorld.Configuration
{
	/// <summary>
	/// Custom configuration section which can be used to configure an instance of <see cref="LinqToLfsWorld.LfsWorldContext"/>.
	/// </summary>
	public class LFSWConfigurationSection : ConfigurationSection
	{
		/// <summary>
		/// Gets or sets the pubstat access ident key from the configuration file.
		/// </summary>
		[ConfigurationProperty("identKey")]
		public string IdentKey
		{
			get { return this["identKey"] as string; }
			set { this["identKey"] = value; }
		}

		/// <summary>
		/// Gets or sets the pubstat premium access flag from the configuration file.
		/// </summary>
		[ConfigurationProperty("premiumPubstatAccess")]
		public bool? PremiumPubstatAccess
		{
			get 
			{
				if (this["premiumPubstatAccess"] != null)
					return (bool?)Convert.ToBoolean(this["premiumPubstatAccess"]);
				else
					return null;
			}
			set { this["premiumPubstatAccess"] = value; }
		}

		/// <summary>
		/// Gets or sets the username.
		/// </summary>
		/// <value>The username.</value>
		[ConfigurationProperty("pubstatUsername")]
		public string Username
		{
			get { return this["pubstatUsername"] as string; }
			set { this["pubstatUsername"] = value; }
		}

		/// <summary>
		/// Gets or sets the password.
		/// </summary>
		/// <value>The password.</value>
		[ConfigurationProperty("pubstatPassword")]
		public string Password
		{
			get { return this["pubstatPassword"] as string; }
			set { this["pubstatPassword"] = value; }
		}

		/// <summary>
		/// Gets or sets the authentication mode.
		/// </summary>
		/// <value>The authentication mode.</value>
		[ConfigurationProperty("authenticationMode", IsRequired=true)]
		public AuthMode AuthenticationMode
		{
			get { return (AuthMode)this["authenticationMode"]; }
			set { this["authenticationMode"] = value; }
		}

		/// <summary>
		/// Gets or sets whether caching is enabled or not.
		/// </summary>
		/// <value>The caching enabled.</value>
		[ConfigurationProperty("cachingEnabled")]
		public bool? CachingEnabled
		{
			get
			{
				if (this["cachingEnabled"] != null)
					return (bool)this["cachingEnabled"];
				else
					return null;
			}
			set { this["cachingEnabled"] = value; }
		}

		/// <summary>
		/// Gets the cache seconds.
		/// </summary>
		/// <value>The cache seconds.</value>
		[ConfigurationProperty("cacheSeconds")]
		public int? CacheSeconds
		{
			get
			{
				if (this["cacheSeconds"] != null)
					return (int)this["cacheSeconds"];
				else
					return null;
			}
		}

	}
}
